// Copyright 2022 Huawei Cloud Computing Technology Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "CaeMsgCode.h"
using namespace std;
static map<int, string> g_codeMap = {{CAE_CONNECTING,                  "Connecting" },
                                     {CAE_CONNECT_SUCCESS,             "Connect success" },
                                     {CAE_SERVER_UNREACHABLE,          "Server unreachable" },
                                     {CAE_RESOURCE_IN_USING,           "Resource in using" },

                                     {CAE_VERIFYING,                   "Verifying" },
                                     {CAE_VERIFY_SUCCESS,              "Verify success" },
                                     {CAE_VERIFY_PARAMETER_MISSING,    "Verify parameter missing" },
                                     {CAE_VERIFY_PARAMETER_INVALID,    "Verify parameter invalid" },
                                     {CAE_VERIFY_AES_KEY_QUERY_FAILED, "Server inner error" },
                                     {CAE_VERIFY_AES_KEY_INVALID,      "Server inner error" },
                                     {CAE_VERIFY_DECRYPT_FAILED,       "Server inner error" },
                                     {CAE_VERIFY_FAILED,               "Server inner error" },
                                     {CAE_VERIFY_SESSION_ID_INVALID,   "Verify session id invalid"},

                                     {CAE_START_SUCCESS,               "Start success" },
                                     {CAE_PARAMETER_MISSING,           "Start parameter missing" },

                                     {CAE_CONNECT_LOST,                "Connect lost" },
                                     {CAE_RECONNECTING,                "Reconnecting" },
                                     {CAE_RECONNECT_SUCCESS,           "Reconnect success" },
                                     {CAE_RECONNECT_PARAMETER_INVALID, "Reconnect parameter invalid" },
                                     {CAE_RECONNECT_SERVER_UNREACHABLE, "Reconnect server unreachable" },
                                     {CAE_RECONNECT_ENGINE_START_ERROR, "Server inner error" },

                                     {CAE_TRAIL_PLAY_TIMEOUT,           "Available time usedup" },
                                     {CAE_NOTOUCH_TIMEOUT,              "Notouch timeout" },
                                     {CAE_HOME_TIMEOUT,                 "Switch background timeout" },
                                     {CAE_DECODE_ERROR,                 "Decode error" },
                                     {CAE_ENGINE_START_FAILED,          "Engine Start failed" },
                                     {CAE_SWITCH_BACKGROUND_SUCCESS,    "Switch backgroud" },
                                     {CAE_SWITCH_BACKGROUND_ERROR,      "Server inner error" },
                                     {CAE_SWITCH_FOREGROUND_SUCCESS,    "Switch foregroud" },
                                     {CAE_INVALID_CMD,                  "Invalid Operation" },
                                     {CAE_BACK_HOME,                    "Back home" },
                                     {CAE_OTHERS_CONNECTED,             "Others connected"},

                                     { CAE_SET_MEDIA_CONFIG_SUCCESS, "Set media config success" },
                                     { CAE_SET_MEDIA_CONFIG_ERROR,   "Set media config error" } };

bool CaeMsgCode::GetMsg(const uint32_t code, string &msg)
{
    for (auto &it : g_codeMap) {
        if (it.first == code) {
            msg = it.second;
            return true;
        }
    }
    return false;
}